package com.jsh.erp.exception;

import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import org.slf4j.Logger;

import javax.annotation.Resource;

/**
 * 封装日志打印，收集日志
 * author: ji shenghua, qq 752718 920
 */
public class JshException {

    public static void readFail(Logger logger, Exception e,String lanCode) {
        if ("zh".equals(lanCode)) {
            logger.error("异常码[{}],异常提示[{}],异常[{}]",
                    ExceptionConstants.DATA_READ_FAIL_CODE, "zh".equals(lanCode) ? ExceptionConstants.DATA_READ_FAIL_MSG : ExceptionConstants.DATA_READ_FAIL_MSG_US, e);
            throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
                    "zh".equals(lanCode) ? ExceptionConstants.DATA_READ_FAIL_MSG : ExceptionConstants.DATA_READ_FAIL_MSG_US);
        }else{
            logger.error("异常码[{}],异常提示[{}],异常[{}]",
                    ExceptionConstants.DATA_READ_FAIL_CODE, "zh".equals(lanCode) ? ExceptionConstants.DATA_READ_FAIL_MSG : ExceptionConstants.DATA_READ_FAIL_MSG_US, e);
            throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
                    "zh".equals(lanCode) ? ExceptionConstants.DATA_READ_FAIL_MSG : ExceptionConstants.DATA_READ_FAIL_MSG_US);
        }
    }

    public static void writeFail(Logger logger, Exception e,String lanCode) {
        if ("zh".equals(lanCode)){
            logger.error("异常码[{}],异常提示[{}],异常[{}]",
                    ExceptionConstants.DATA_WRITE_FAIL_CODE,"zh".equals(lanCode) ? ExceptionConstants.DATA_WRITE_FAIL_MSG : ExceptionConstants.DATA_WRITE_FAIL_MSG_US,e);
            throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
                    "zh".equals(lanCode) ? ExceptionConstants.DATA_WRITE_FAIL_MSG : ExceptionConstants.DATA_WRITE_FAIL_MSG_US);
        }else {
            logger.error("异常码[{}],异常提示[{}],异常[{}]",
                    ExceptionConstants.DATA_WRITE_FAIL_CODE,"zh".equals(lanCode) ? ExceptionConstants.DATA_WRITE_FAIL_MSG : ExceptionConstants.DATA_WRITE_FAIL_MSG_US,e);
            throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
                    "zh".equals(lanCode) ? ExceptionConstants.DATA_WRITE_FAIL_MSG : ExceptionConstants.DATA_WRITE_FAIL_MSG_US);
        }
    }


}
